import { encryptByAES } from '@/utils/aes'
import request from '@/utils/request'
import { getToken } from '@/utils/auth'

// 上传
export function uploadData(formData) {
  formData.append('username', getToken('name'))
  formData.append('userId', getToken('id'))
  return request({
    url: '/user/upload',
    method: 'post',
    data: formData
  })
}

// 上传记录
export function getNodes(params) {
  params.user_id = getToken('id')
  return request({
    url: '/user/upinfo',
    method: 'post',
    data: params
  })
}

// 分析数据
export function analyze(params) {
  params.user_id = getToken('id')
  return request({
    url: '/user/analyze',
    method: 'post',
    data: params
  })
}

// 分析记录
export function getAnalyzeList(params) {
  return request({
    url: '/user/upinfo',
    method: 'post',
    data: params
  })
}

// 查询钱包余额
export function getBalance(params) {
  params.address = getToken('address')
  return request({
    url: '/user/queryBalance',
    method: 'post',
    data: params
  })
}

// 获取钱包交易记录
export function getRechargeRecord(params) {
  params.user_id = getToken('id')
  return request({
    url: '/user/rechargeRecord',
    method: 'post',
    data: params
  })
}

// 充值、提现
export function postRecharge(params) {
  params.user_id = getToken('id')
  return request({
    url: '/user/recharge',
    method: 'post',
    data: params
  })
}

// 修改登录密码
export function editLoginPwd(params) {
  return request({
    url: '/userinfo/modifyPassword',
    method: 'post',
    data: {
      username: getToken('name'),
      password: encryptByAES(params.password),
      newPassword: encryptByAES(params.newPassword)
    }
  })
}

// 设置支付密码
export function setPayPwd(params) {
  params.user_id = getToken('id')
  return request({
    url: '/user/setPayPW',
    method: 'post',
    data: params
  })
}
